﻿package com.wandian.util
{  
	import com.wandian.data.GameData;
	
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.ByteArray;

    public class TextControl extends Object
    {

        public function TextControl()
        {
            return;
        }

        public static function checkStrByte(msg:String) : int
        {
            if (msg == null)
            {
                return -1;
            }
            var bytes:ByteArray = new ByteArray();
            bytes.writeMultiByte(msg, "utf8");
            return bytes.length;
        }

        public static function isSameForText(param1:String, param2:String) : Boolean
        {
            if (param1 == param2)
            {
                return true;
            }
            return false;
        }

        public static function checkStrLen(param1:String, param2:int, param3:int) : String
        {
            if (param1.length < param2)
            {
                return GameData.tip["ENTER_LEN_MIN_TIP"] + param2;
            }
            if (param1.length > param3)
            {
                return GameData.tip["ENTER_LEN_MAX_TIP"] + param2;
            }
            return "";
        }

        public static function isEmail(param1:String) : Boolean
        {
            var _loc_3:Array = null;
            var _loc_2:* = param1.split("@");
            if (_loc_2.length == 2)
            {
                if (_loc_2[0].length > 0)
                {
                    _loc_3 = _loc_2[1].split(".");
                    if (_loc_3.length >= 2)
                    {
                        if (_loc_2[1].charAt(0) != ".")
                        {
                            if (_loc_2[1].charAt((_loc_2[1].length - 1)) != ".")
                            {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }

        public static function isTellNumber(param1:String) : Boolean
        {
            if (!isNaN(int(param1)))
            {
                isNaN(int(param1));
            }
            if (param1.length == 11)
            {
            }
            if (param1.charAt() != "1")
            {
                return false;
            }
            return true;
        }

        public static function initTxtTip(param1:TextField, param2:String = "") : void
        {
            var downTextHandler:Function;
            var textOutHandler:Function;
            var txt:* = param1;
            var initTip:* = param2;
            downTextHandler = function (event:MouseEvent) : void
            {
                var _loc_2:* = txt.text;
                if (_loc_2 == initTip)
                {
                    txt.text = "";
                }
                return;
            }
            ;
            textOutHandler = function (event:MouseEvent) : void
            {
                var _loc_2:* = txt.text;
                if (_loc_2 == "")
                {
                    txt.text = initTip;
                    Texas.I._mcWindosView.stage.focus = Texas.I._mcWindosView.stage;
                }
                return;
            }
            ;
            txt.addEventListener(MouseEvent.MOUSE_DOWN, downTextHandler);
            txt.addEventListener(MouseEvent.MOUSE_OUT, textOutHandler);
            txt.text = initTip;
            return;
        }

        public static function setAddSubTxt(param1:Sprite, param2:TextField, param3:int = 0, param4:int = 100) : void
        {
            var onAddHandler:Function;
            var onSubHandler:Function;
            var changeTxtHandler:Function;
            var parentMc:* = param1;
            var txt:* = param2;
            var min:* = param3;
            var max:* = param4;
            onAddHandler = function (event:MouseEvent) : void
            {
                showNum(1);
                return;
            }
            ;
            onSubHandler = function (event:MouseEvent) : void
            {
                showNum(-1);
                return;
            }
            ;
            var showNum:* = function (param1:int) : void
            {
                var _loc_2:* = int(txt.text);
                _loc_2 = _loc_2 + param1;
                if (_loc_2 >= min)
                {
                }
                if (_loc_2 > max)
                {
                    return;
                }
                txt.text = _loc_2.toString();
                parentMc.dispatchEvent(new Event(Event.CHANGE));
                return;
            }
            ;
            changeTxtHandler = function (event:Event) : void
            {
                parentMc.dispatchEvent(new Event(Event.CHANGE));
                return;
            }
            ;
            txt.restrict = "1-9";
            var addBtn:* = GameData.getButton("AddBtn");
            var subBtn:* = GameData.getButton("SubBtn");
            parentMc.addChild(addBtn);
            parentMc.addChild(subBtn);
            addBtn.x = txt.x + txt.width;
            addBtn.y = txt.y;
            subBtn.x = txt.x - subBtn.width;
            subBtn.y = txt.y;
            txt.addEventListener(Event.CHANGE, changeTxtHandler);
            addBtn.addEventListener(MouseEvent.CLICK, onAddHandler);
            subBtn.addEventListener(MouseEvent.CLICK, onSubHandler);
            return;
        }

        public static function initAddSubTxt(param1:DisplayObject, param2:TextField, param3:SimpleButton, param4:SimpleButton, param5:int = 0, param6:int = 100, param7:int = 0) : void
        {
            var onAddHandler:Function;
            var onSubHandler:Function;
            var changeTxtHandler:Function;
            var mc:* = param1;
            var txt:* = param2;
            var addBtn:* = param3;
            var subBtn:* = param4;
            var min:* = param5;
            var max:* = param6;
            var step:* = param7;
            onAddHandler = function (event:MouseEvent) : void
            {
                showNum(1);
                return;
            }
            ;
            onSubHandler = function (event:MouseEvent) : void
            {
                showNum(-1);
                return;
            }
            ;
            var showNum:* = function (param1:int) : void
            {
                var _loc_2:* = int(txt.text);
                _loc_2 = _loc_2 + param1 * step;
                checkNum(_loc_2);
                return;
            }
            ;
            changeTxtHandler = function (event:Event) : void
            {
                var _loc_2:* = int(txt.text);
                checkNum(_loc_2);
                return;
            }
            ;
            var checkNum:* = function (param1:int) : void
            {
                if (param1 < min)
                {
                    param1 = min;
                }
                if (param1 > max)
                {
                    param1 = max;
                }
                txt.text = param1.toString();
                mc.dispatchEvent(new Event(Event.CHANGE));
                return;
            }
            ;
            txt.restrict = "0-9";
            if (step == 0)
            {
                step = max / 10;
            }
            txt.addEventListener(Event.CHANGE, changeTxtHandler);
            addBtn.addEventListener(MouseEvent.CLICK, onAddHandler);
            subBtn.addEventListener(MouseEvent.CLICK, onSubHandler);
            checkNum(1);
            return;
        }

    }
}
